<?php

namespace app\admin\model;

use think\Model;


class Agentorder extends Model
{

    

    

    // 表名
    protected $name = 'order';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'source_text',
        'status_text',
        'create_time_text',
        'pay_time_text',
        'bucket_text',
        'delivery_type_text',
        'delivery_time_text',
        'delivery_to_time_text'
    ];
    

    
    public function getSourceList()
    {
        return ['0' => __('Source 0'), '1' => __('Source 1')];
    }

    public function getStatusList()
    {
        return ['0' => __('Status 0'), '1' => __('Status 1'), '2' => __('Status 2'), '3' => __('Status 3'), '4' => __('Status 4'), '5' => __('Status 5')];
    }

    public function getBucketList()
    {
        return ['0' => __('Bucket 0'), '1' => __('Bucket 1')];
    }

    public function getDeliveryTypeList()
    {
        return ['0' => __('Delivery_type 0'), '1' => __('Delivery_type 1')];
    }


    public function getSourceTextAttr($value, $data)
    {
        $value = $value ?: ($data['source'] ?? '');
        $list = $this->getSourceList();
        return $list[$value] ?? '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ?: ($data['status'] ?? '');
        $list = $this->getStatusList();
        return $list[$value] ?? '';
    }


    public function getCreateTimeTextAttr($value, $data)
    {
        $value = $value ?: ($data['create_time'] ?? '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getPayTimeTextAttr($value, $data)
    {
        $value = $value ?: ($data['pay_time'] ?? '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getBucketTextAttr($value, $data)
    {
        $value = $value ?: ($data['bucket'] ?? '');
        $list = $this->getBucketList();
        return $list[$value] ?? '';
    }


    public function getDeliveryTypeTextAttr($value, $data)
    {
        $value = $value ?: ($data['delivery_type'] ?? '');
        $list = $this->getDeliveryTypeList();
        return $list[$value] ?? '';
    }


    public function getDeliveryTimeTextAttr($value, $data)
    {
        $value = $value ?: ($data['delivery_time'] ?? '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getDeliveryToTimeTextAttr($value, $data)
    {
        $value = $value ?: ($data['delivery_to_time'] ?? '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setCreateTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setPayTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setDeliveryTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setDeliveryToTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


}
